package com.cskaoyan.order.biz.handler;

import com.cskaoyan.mall.commons.exception.ValidateException;
import com.cskaoyan.mall.order.constant.OrderRetCode;
import com.cskaoyan.order.biz.context.CreateOrderContext;
import com.cskaoyan.order.biz.context.TransHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ValidateHandler extends AbstractTransHandler {


    @Override
    public boolean isAsync() {
        return false;
    }

    @Override
    public boolean handle(TransHandlerContext context) {
        //必要的参数不能为空
        CreateOrderContext createOrderContext = (CreateOrderContext) context;
        if (null==createOrderContext.getUserId()||null==createOrderContext.getAddressId()
        ||null==createOrderContext.getTel()||null==createOrderContext.getUserName()){
            //此时应该抛出异常
            throw  new ValidateException(OrderRetCode.REQUISITE_PARAMETER_NOT_EXIST.getCode(),
                    OrderRetCode.REQUISITE_PARAMETER_NOT_EXIST.getMessage());
        }
        return true;
    }
}
